<?php

$page_title = "Whos On";
$rank_check = 0;
include "header.inc.php";

if ($popup == "true") { print "<html><head><title>$page_title</title></head><body bgcolor=$reallyLight>"; $popupLink = " TARGET=_blank"; }
if ($popup != "true") { print "$openHTML"; }

$usersOn3 = mysql_query("SELECT id,userid FROM online WHERE last_visit >= '$onlineTimeLimit' AND game = '$game' AND online_type = '0'");
while ($getUsersOn = mysql_fetch_array($usersOn3))
{
	$usersOn2 = fetch("SELECT id,rank,username,display_name,premium,display_prem FROM members2 WHERE id = '$getUsersOn[userid]'");

	$members_profiles = fetch("SELECT * FROM members_profiles2 WHERE username = '$usersOn2[username]' AND game = '$game'");
	
	$id = $usersOn2[id];

	if ($members_profiles[date_registered] >= $timestamp - 86400) { $new[$id] = "<font color=\"#CC9900\" size=-1>(New!)</font>"; }

	$display_rank = $usersOn2[rank];
	$display_rankArray = array('', '', '', '', '<font color=#99CCFF size=-1>(Police)</font>', '<font color=#3399FF size=-1>(Moderator)</font>', '<font color=#0000FF size=-1>(Staff)</font>',  '<font color=#0000FF size=-1>(Admin)</font>');
	$display_rank = $display_rankArray[$display_rank];	

	if ($usersOn2[premium] == 1)
	{
		$display_prem[$id] = "<a$popupLink href=upgrade.php?game=$game><font color=#0000FF size=-1><b>(Premium)</b></font></a> ";
		if ($usersOn2[display_prem])
		{
			$usersOn2[display_name] = $usersOn2[display_prem];
		}
	}

	$gender = $members_profiles[gender];
	$genderArray = array("<img src=images/icons/undecided.gif>", "<img src=images/icons/female.gif>", "<img src=images/icons/male.gif>");
	$gender = $genderArray[$gender];	

	$mailSettings = $members_profiles[mail_settings];
	$mailSettingsArray = array(
	"<a$popupLink href=mail_send.php?game=$game&send_to=$usersOn2[username]><img src=images/icons/mail.gif></a>", 
	"<a$popupLink href=mail_send.php?game=$game&send_to=$usersOn2[username]><img src=images/icons/mail.gif></a>", 
	"");
	$mailSettings = $mailSettingsArray[$mailSettings];	
	
	$bud = "<a$popupLink href=buds.php?game=$game&bud=$usersOn2[username]><img src=images/icons/bud.gif></a>";
	
	$listUsersOn .= "<tr><td valign=right><a$popupLink href=$base_url/user_profile.php?game=$game&user=$usersOn2[username]>$usersOn2[display_name]</a></td> 
<td width=14>$gender</td>
<td width=14>$mailSettings</td>
<td width=14>$bud</td>
<td>$display_rank$new[$id]$display_prem[$id]</td></tr>";
}

$numGuests = fetch("SELECT count(id) AS id FROM online WHERE last_visit >= '$onlineTimeLimit' AND game = '$game' AND online_type = '1'");

ECHO <<<END

<br><br>
<P align=center><TABLE BGCOLOR="$topAndBottomBG" CELLSPACING=1 CELLPADDING=0 WIDTH=500>
   <TR>
      <TD WIDTH=500 HEIGHT=50>
         <CENTER><FONT SIZE="+3" COLOR="$topAndBottomText"><B>--$countUsersOn Users Online--</B></FONT></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR="$maincellColor">
      <TD WIDTH=500>
         <p align=center>
         <table>
         $listUsersOn
         </Table>
      	 </p>
      	 <p><font color=blue>+ $numGuests[id] Guests Online</font></p>
      	 </CENTER>
      </TD>
   </TR>
</TABLE>
</P>
<br>

END;


if ($popup != "true") { print "$closeHTML"; }
if ($popup == "true") { print "<p align=center>&copy;</p></body></html>"; }

?>
